<?php 
session_start();
include('config.inc.php');
// session variable
$sess_id=$_SESSION['sess_id'];
$sess_user=$_SESSION['sess_user'];
$sess_status=$_SESSION['sess_status'];
$flag = $_SESSION['sess_flag'];

echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\" />";
?>
<html>
<head>
<title>FCR</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/script.js"></script>
<link rel="stylesheet" type="text/css" href="epoch_styles.css" />
<script type="text/javascript" src="js/epoch_classes.js"></script>
</head>
<?
if ($sess_id<>session_id() || $sess_user=="" || $sess_status<>"active") {
	echo "<body>";
}else{
	echo "<body onload=\"javascritp:showPage();\">";
}
?>
<div align="center">
<?php 
//<!-- Header -->
echo "<div id=\"header\">
    	<div id=\"logo\">
			TT&T Public Co., Ltd.
    	</div>
        <div id=\"address\" align=\"left\">".$address."
        </div>
        <div id=\"menu\">
        	<a href=\"index.php\" id=\"on\">หน้าแรก</a>  
			<a href=\"http://web.ttt.co.th\">Intranet</a>
			<a href=\"admin/index.php\">Control panel</a>
			<a href='logout.php'>logout</a>
        </div>
      </div>";
//<!-- Body -->
echo "<div id=\"content\" align=\"justify\">";
/*if ($sess_id<>session_id() || $sess_user=="" || $sess_status<>"active") {
		//header( "Location: login.php");exit();
		include('login.php');
	}else{
*/
if ($sess_id <> session_id() || $sess_user == "" || $sess_status <> "active") {
		//echo "<div id='sectoruser' style='padding:10px 0px 10px 20px;'>";
		include("login.php");
		echo "</div>";
		exit();
	}
	
$loginuser = mysql_num_rows(mysql_query("SELECT * FROM USERS u join flag_detail fd on u.flag=fd.flag_id WHERE USERNAME = '$sess_user'"));
$getu = mysql_fetch_array(mysql_query("SELECT * FROM USERS u join flag_detail fd on u.flag=fd.flag_id WHERE USERNAME = '$sess_user'"));
if($loginuser != 0){
echo "<div id='sectoruser' style='padding:10px 0px 10px 20px;'><table width=\"500\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
    <td valign=\"top\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
      <tr>
        <td width=\"42%\" style='padding:5px 0px 5px 10px;'><small>สวัสดี คุณ ".$getu['name']."</small>
          </td>
      <td width=\"31%\" style='padding:5px 0px 5px 10px;'><small>หน่วยงาน ".$getu['unit_code']."</small>
        </td>
      <td width=\"27%\" style='padding:5px 0px 5px 10px;'><small>จังหวัด ".$getu['pnthai']."</small>
        </td>
      </tr>
      <tr>
      <td style='padding:5px 0px 5px 10px;'><small>อีเมลล์ ".$getu['username']."@ttt.co.th</small></td>
      <td width=\"31%\" style='padding:5px 0px 5px 10px;'><small>โทรศัพท์ ".$getu['tel']."</small></td>
      <td width=\"27%\" style='padding:5px 0px 5px 10px;'><small>โทรสาร ".$getu['fax']."</small></td>
      </tr>
      <tr>
      <td  style='padding:5px 0px 5px 10px;'><small>สถานะ ".$getu['flag_name']."</small></td>
      <td width=\"31%\" style='padding:5px 0px 5px 10px;'><small>&nbsp;</small></td>
      <td width=\"27%\" style='padding:5px 0px 5px 10px;'><small><a href='logout.php' style='text-decoration:none;'>ออกจากระบบ</a></small></td>
      </tr>
    </table></td>
  </tr>
</table></div>";
}else{
	echo "<div id='sectoruser' style='padding:10px 0px 10px 20px;'><table width=\"500\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
  <tr>
    <td valign=\"top\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
      <tr>
        <td width=\"42%\" style='padding:10px 0px 10px 0px;' align='center'><small>คุณยังไม่ได้เข้าสู่ระบบ  <a href='login.php' style='text-decoration:none;'>เข้าสู่ระบบที่นี่</a></small></td>
      </tr>
    </table></td>
  </tr>
</table></div>";
}
echo "<div id=\"menutabs\">";
echo "<a href=\"javascript:showPage('welcome.php');\">อุปกรณ์สำนักงาน</a>";
echo "<a href=\"javascript:showPage('process.php');\">แจ้งเหตุเสีย</a>";
echo "<a href=\"javascript:showPage('search.php');\">ติดตามแจ้งเหตุเสีย</a>";
echo "<a href=\"javascript:showPage('showdetail.php');\">ดูประวัติการแจ้งเหตุ</a>";
//-- <a href="#" class="tabon">Software</a><a href="#">Hardware</a><a href="#">Periferals</a><a href="#">Laptops</a> -->
echo "</div><br/>
		<div id='leftshow'></div>		
		<div id='left'></div>
        <div id=\"showright\"></div>
        <div style=\"clear:both\"></div>";
		//}
echo "</div>";
//<!-- Footer -->
echo $footer;
?>
</div>
</body>
</html>
